#include "file_operate.h"

#include "file_description.h"

#include <cstdint>
#include <memory>
#include <unistd.h>

FileOperate::FileOperate(std::shared_ptr<Description> description)
{
    m_description = description;
}

int FileOperate::Read(uint8_t * data, int length) const
{
    int result = read(m_description->DescriptionData(), data, length);
    if (result <= 0)
    {
        result = 0;
    }
    return result;
}

int FileOperate::Write(const uint8_t * data, const int length) const
{
    int result = write(m_description->DescriptionData(), (const void*)data, length);
    if (result < 0)
    {
        result = -1;
    }
    return result;
}
